﻿/********************************************************************************
** @ Date:2025/05/27
** @ Author: Gaojia
** @ Description: 数据库操作类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef CSqlOper_H
#define CSqlOper_H
#include "CRBaseData.h"
#include "CPublicData.h"
class CDevDataBase;
class CDevDataCam;
struct SSensorInfo;
extern QString selDeviceInfo(QString sId,int & nId,QString &sErr);   //使用设备id 查询设备驱动内部的GUID
extern bool intsertDeviceInfo(CDevDataBase* pDevDataRob, QString& sErr);   //使用设备id 插入设备
extern bool selRobHostById(CDevDataBase *pDevDataRob, QString& sErrMsg);
extern bool selectRobRollerNoConfigByID(CDevDataBase *pDevDataRob, QString& sErrMsg);                                  //根据机器人编号获取机器人托辊号配置
extern bool selRobPanTiltById(CDevDataBase *pDevDataRob, QString& sErrMsg);
extern bool selectRobSensorByID(CDevDataBase *pDevDataRob, QString& sErrMsg);
extern bool selectIoByID(CDevDataBase *pDevDataRob, QString& sErrMsg);
extern QVector<CTaskInfo> selectTaskInfoEx(QString sSceneGuid, QString& sErrMsg);
extern QMap<int, QString> selectTaskRule(QString sSceneGuid, QString &sErrMsg);    //根据场景Guid查询场景的任务规则 返回  座位和id   
extern bool selCurrTaskExecByID(const QString sSecneGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);        //根据场景ID获取当天的任务执行记录
extern bool selTaskRuleByTimeType(QString sSceneGuid, QVector<int> vecTimeType, QVector<QSqlRecord>& vecRecord, QString sErrMsg);//根据场景Guid、timeType数组获取任务规则
extern QVector<CTaskInfo> selTaskInfoByTaskID(QString sSceneGuid, QVector<QString> vecTaskGuid, QString& sErrMsg);
extern bool selectPloItemCamerBySceneID(const QString sSceneGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);				 //根据场景ID获取云台巡检项map
extern bool selectPloItemSensorBySceneID(const QString sSceneGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
extern bool selectImageItemExecCotdet(const QString sTaskExecGuid, int nItemTypeCode, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);//根据任务执行记录ID和巡检项类型查询巡检项执行记录表
extern bool selectSensorItemExecByTaskExecID(const QString sSecneGuid, QString sTaskExecGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);//根据场景ID获取传感器巡检项执行记录表
extern bool selectImageItemExecByTaskExecID(const QString sSecneGuid, QString sTaskExecGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);//根据场景ID获取云台巡检项执行记录表
extern bool selectTaskExec(const CTaskExecInfo info, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
/**
* @ Author: Gaojia
* @ Description: 获取区域数据
*/
extern bool selAreaByGuid(const QString sSceneGuid, CPolArea* pPolArea, QString& sErrMsg);    //根据场景ID查找巡检区域
extern bool selPointByGuiD(const QString sSceneGuid, QMap<QString, CPolPoint*>& mapPolPoint, QString& sErrMsg);            //根据场景ID获取巡检点map
extern bool selItemCamerByGuid(const QString sSceneGuid, QMap<QString, CPolPoint*>& mapPolPoint, QString& sErrMsg);        //根据场景ID获取云台巡检项map
extern bool selItemSensorByGuid(const QString sSceneGuid, QMap<QString, CPolPoint*>& mapPolPoint, QString& sErrMsg);       //根据场景ID获取传感器巡检项map
extern bool insertTaskExecInfoEx(CTaskInfo cTaskInof);
/**
* @ Author: Gaojia
* @ Description: 任务相关
*/
extern bool selectAllTaskInfo(const QString sSceneGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
extern bool selectPerTaskInfo(const QString sSceneGuid, QVector<QSqlRecord>& vecRecord, QString &sErrMsg);
extern bool selectTaskExecByDate(const QString sTaskGuid, const QString sStartDate, QVector<CTaskExecInfo>& vecTaskExec, QString &sErrMsg);                  //根据任务GUID 获得对应日期的任务执行结果
extern bool selectTaskExecByDateTime(const QString sTaskGuid, const QString sStartDateTime, CTaskExecInfo& uTaskExec, QString &sErrMsg);          //根据任务GUID 获得对应日期的任务执行结果
extern bool selectTaskRule(QString sSceneGuid, QVector<QSqlRecord>& vecRecord, QString sErrMsg);//根据场景Guid查询场景的任务规则
extern QVector<CTaskInfo> selectTaskInfoCycTask(QString sSceneGuid, QString& sErrMsg); 																																			
extern bool updateTaskRule(QString sSceneGuid, QVector<int> vecTimeType,QString sNewTaskguid, QString sErrMsg);//根据场景Guid查询场景的任务规则
extern bool addTaskInfo(CTaskInfo& taskInfo, QString& sErrMsg);
extern bool updateTaskInfo(CTaskInfo& taskInfo, QString& sErrMsg);  
extern bool selectTaskInfo(const CTaskInfo taskInfo, QVector<QSqlRecord>& vecRecord, QString& sErrMsg); 
extern bool deleteTaskRule(QString sSceneGuid, QString sTaskguid, QString sErrMsg);//将指定的任务在座位中清空，使用的是update
extern bool deleteTaskInfoByTaskID(QString sTaskGuid, QString& sErrMsg);
extern bool updateTaskExecInfo(CTaskExecInfo *pTaskExecInfo);
extern bool insertItemExecResult(CTaskExecInfo *pTaskExecInfo);//插入巡检项执行结果
extern bool insertSensorItemResult(CItemResultSensor *pItemResultSensor);//更新传感器结果数据到数据库
extern bool insertCamerItemResult(CItemResultCamera *pItemResultCamera);//更新云台结果数据到数据库
extern bool insertTaskExecInfo(CTaskExecInfo *pTaskExecInfo);
extern bool updateCollectCount(CItemResultCamera *pItemResultCamera);//更新持续巡检报警项数
extern bool updateCollectCountEx(QString sGuid, int nAlarmCount, int nExecCount);//更新持续巡检报警项数和持续巡检项检测项数
extern bool selectSensorItemExecByItemExecID(const QString sItemExecGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);//根据巡检项执行记录ID获取传感器巡检项执行记录表
extern bool selectImageItemExecByItemExecID(const QString sItemExecGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);//根据巡检项执行记录ID获取云台巡检项执行记录表
/**
* @ Author: Gaojia
* @ Description: 模板管理
*/
extern bool selectTemplateBySceneID(const QString sSceneGuid, QMap<QString, CTemplateInfo*>& mapTemplate, QString& sErrMsg);        //根据场景ID获取模版map
extern bool deleteTemplateByFixedGuid(QString& sTemplateFixedId, QString& sErrMsg);   //根据GUID删除模版
extern bool addTemplate(CTemplateInfo& templateInfo, QString& sErrMsg);               //添加模版
extern bool setTemplateOldByFixedId(QString sTemplateFixedId, QString& sErrMsg);      //根据模版固定ID将所有此ID的模版都设置为不是最新的
CTemplateInfo selectTemplateInfo(QString sTemplateFixedId, QString& sErrMsg);         //使用模板编码查询模板信息

/**
* @ Author: Gaojia
* @ Description: 巡检地图相关
*/
bool updatePloItemSensorByItemID(const CPolItemSensor& item, QString& sErrMsg);         //根据根据巡检项GUID更新传感器巡检项
bool updatePloItemCamerByItemID(const CPolItemCamer& item, QString& sErrMsg);
extern bool addPloItemSensor(const CPolItemSensor& item, QString& sErrMsg);               //添加传感器巡检项
extern bool addPloItemCarmer(const CPolItemCamer& item, QString& sErrMsg);                         //添加云台巡检项
extern bool addPolPointInfo(CPolPoint* pPoint, QString& sErrMsg);
extern bool delPolPoint(QString sPointGuid, QString& sErrMsg);                         //删除巡检点    
extern bool delPolPoint(QString sSceneGuid, QVector<QString>vecPointGuid, QString& sErrMsg);//批量删除巡检点   
extern bool delPolItem(QString sSceneGuid, QVector<QString>vecPointGuid, QString& sErrMsg);    //批量删除巡检项  
extern bool delPolItemEx(QString sSceneGuid, QString sPointGuid, QVector<QString>vecItemGuid, QString& sErrMsg); //批量删除巡检项  
extern bool updatePointName(QString sPointGuid, QString sPointName, QString& sErrMsg);               //修改巡检点名称
extern bool updatePointLocation(QString sPointGuid, double dLocation, QString& sErrMsg);               //修改巡检点位置
extern bool updatePointCharge(QString sPointGuid, int nIsCharge, QString& sErrMsg);                  //修改巡检点是否为充电桩

//创建机器人
extern bool addRobHost(QString sSceneGuid, CDevDataBase* pDevDataRob, QString& sErrMsg);               //添加一个机器人
extern bool addRobPanTilt(CDevDataCam* pDevDataRob, QString& sErrMsg);                                 //添加云台设备
extern bool addRobModbus(QString sRobGuid, QList<QStringList> listModbusData, QString& sErrMsg);       //添加机器人Modbus数据
extern bool addRobSensorMulti(QString sRobGuid, QVector<SSensorInfo> vecSensor, QString& sErrMsg);     //插入机器人传感器

//删除机器人
extern bool deleteDeviceInfo(QString sId);

/**
* @ Author: Gaojia
* @ Description: 机器人参数配置
*/
extern bool selectRobConfig(QString sGuid, CDevDataBase* pDevDataRob); //获取机器人数据库里面的配置参数
extern bool updateRobHostDevice(CDevDataBase* pDevData, QString& sErrMsg);//更新设备主机配置表
bool extern updatePanTiltConfig(CDevDataCam* pDevData, QString& sErrMsg);//更新云台配置表
class CSqlOper
{
public:
	CSqlOper();	
	~CSqlOper();
};

#endif